import Vue from 'vue'
import Vuex from 'vuex'
import api from '@/common/vmeitime-http/'
import util from '@/common/util'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		userInfo: uni.getStorageSync('userInfo')
	},
	mutations: {
		
	},
	actions: {
		dispatchUserInfo: async function ({ commit, state}) {
			let res = await api.userInfo({
				key: util.getKey(),
				uid: util.getUid(),
			})
			if(res && res.data && res.data.data){
				state.userInfo = res.data.data
				uni.setStorageSync('userInfo', res.data.data)
			}
		}
	}
})

export default store
